package pl.org.lutra.planner.gui.toolbar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import pl.org.lutra.planner.Planner;
import pl.org.lutra.planner.model.ModelEvent;
import pl.org.lutra.planner.model.ModelListener;

public class CalculateButton extends ToolbarButton implements ModelListener, ActionListener {
    private static final long serialVersionUID = -4904443305765169099L;
    
    private Planner planner = Planner.getInstance();
    
    public CalculateButton() {
        super("toolbar.button.calculate");
        
        setEnabled(false);
        
        planner.getInput().addModelListener(this);
        addActionListener(this);
    }
    
    public void prepareToolbarButton() {
        
    }
    
    @Override
    public void inputHasChanged(ModelEvent event) {
        setEnabled(true);
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        setEnabled(false);
        planner.calculate();
    }
    
    @Override
    public void calculationFinished(ModelEvent event) {
    }
    
}
